<?php
$id=$_GET['id'];
if(isset($_POST['ok'])){
	$u=$_POST['username'];
	$p=$_POST['pass'];	
	if($u){
		$sql="select * from user where username='$u' and uid !='$id'";
		$query=mysql_query($sql);
		if(mysql_num_rows($query)>0){
			echo "Đã tồn tại tên này";
		}else{
			if($p){
				$p=md5($p);
				$sql="update user set username='$u',password='$p' where uid='$id'";
			}else{
				$sql="update user set username='$u' where uid='$id'";
			}
			$query=mysql_query($sql);
			header('location:index.php?page=list_user');
			exit();
		}	
	}
}
$sql="select * from user where uid=$id";
$query=mysql_query($sql);
$data=mysql_fetch_assoc($query);
$name=$data["username"];
$pass=$data["password"];
?>
<div id='err'></div>
<form method="post" onsubmit="return validate_edit_user(this);">
<table id='tablemenu'>
	<tr><th>Name:</th><td><input type="text" name='username' size="25" value="<?php echo $name;?>" /></td></tr>
	<tr><th>Pass:</th><td><input type="password" name="pass" size="25" /></td></tr>
	<tr><th>Confirm pass:</th><td><input type="password" name="pass2"  size="25"/></td></tr>
	<tr><td>&nbsp;</td><td><input type="submit" name='ok' value="Submit" /></td></tr>
</table>
</form>